#ifndef STRING_H
#define STRING_H
#include <iostream>
#include <cstring>

using namespace std;
class String
{
private:
public:
    //  define your own private members
    int *cnt;
    char *data;


    String() {}
    String(const char *);
    ~String();
    String(const String &str);
    String &operator=(const String &str);
    int operator==(const String &str) const;
    String operator+(const String &str) const;
    int operator==(const char *str) const;
    int length() const;
    const char *getRaw() const;
    int refCount() const;
};

String::String(const char *c)
{
    data = new char[strlen(c) + 1];
    strcpy(data, c);
    cnt = new int(1);
}

String::~String()
{
    (*cnt)--;
    if (*cnt == 0)
    {
        delete[] data;
        delete cnt;
    }
}

String::String(const String &str)
{
    data = str.data;
    cnt = str.cnt;
    (*cnt)++;
}

String &String::operator=(const String &str)
{
    (*cnt)--;
    if (*cnt == 0)
    {
        delete[] data;
        delete cnt;
    }
    data = str.data;
    cnt = str.cnt;
    (*cnt)++;
    return *this;
}
int String::operator==(const String &str) const
{
    if (strcmp(data, str.data) == 0)
        return 1;
    else
        return 0;
}

int String::operator==(const char *str) const
{
    if (strcmp(data, str) == 0)
        return 1;
    else
        return 0;
}
String String::operator+(const String &str) const
{
    String s;
    s.data = new char[strlen(data) + strlen(str.data) + 1];
    strcpy(s.data, data);
    strcat(s.data, str.data);
    return s;
}
int String::length() const
{
    return strlen(data);
}
const char *String::getRaw() const
{
    return data;
}
int String::refCount() const { return *cnt; }

#endif